package com.ren.service.core.rest;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ren.common.result.R;
import com.ren.service.core.model.po.UserInfoPO;
import com.ren.service.core.model.vo.UserInfoLockReqVO;
import com.ren.service.core.model.vo.UserInfoQueryReqVO;
import com.ren.service.core.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author RenGaoshuai
 * @date 2023/8/8 14:27
 * @description 用户模块
 */
@RestController
@RequestMapping("/admin/core/userinfo")
public class AdminUserInfoController {

    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 用户分页查询
     *
     * @param reqVO
     * @return
     */
    @PostMapping("/page")
    public R listPage(@RequestBody UserInfoQueryReqVO reqVO) {
        Page<UserInfoPO> pageParam = new Page<>(reqVO.getPage(), reqVO.getLimit());
        IPage<UserInfoPO> userInfoPOIPage = userInfoService.listPage(pageParam, reqVO);
        return R.ok().data("pageModel", userInfoPOIPage);
    }

    /**
     * 用户锁定与解锁
     *
     * @param reqVO
     * @return
     */
    @PostMapping("lock")
    public R lock(@RequestBody UserInfoLockReqVO reqVO) {
        int i = userInfoService.lock(reqVO);
        if (i > 0) {

            return R.ok().message(reqVO.getStatus() == 1 ? "解锁成功" : "锁定成功");
        } else {
            return R.error().message(reqVO.getStatus() == 1 ? "解锁失败" : "锁定失败");
        }
    }
}
